package com.lk.lkappearance.service.impl;

import com.lk.lkappearance.common.AbstractBaseService;
import com.lk.lkappearance.mapper.AlarmLedgerMapper;
import com.lk.lkappearance.model.AlarmLedger;
import com.lk.lkappearance.service.AlarmLedgerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AlarmLedgerServiceImpl extends AbstractBaseService implements AlarmLedgerService {

    @Autowired
    private AlarmLedgerMapper alarmLedgerMapper;


    /**
     * 新增报警信息
     *
     * @param alarmLedger
     * @return
     */
    @Override
    public Map<String, Object> add(AlarmLedger alarmLedger) {
        try {
            alarmLedgerMapper.insertSelective(alarmLedger);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     * 修改报警信息
     *
     * @param alarmLedger
     * @return
     */
    @Override
    public Map<String, Object> modify(AlarmLedger alarmLedger) {
        try {
            alarmLedgerMapper.updateByPrimaryKeySelective(alarmLedger);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     * 删除报警信息
     *
     * @param alarmId
     * @return
     */
    @Override
    public Map<String, Object> delete(String alarmId) {
        try {
            alarmLedgerMapper.deleteByPrimaryKey(alarmId);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().getResult();
    }

    /**
     * 得到报警台账列表
     *
     * @param alarmLedger
     * @return
     */
    @Override
    public Map<String, Object> getList(AlarmLedger alarmLedger) {
        Map<String, Object> result = new HashMap<>();
        try {
            List<AlarmLedger> list = alarmLedgerMapper.getList(alarmLedger);
            result.put("list",list);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return success().setData(result).getResult();
    }

    /**
     * 处置报警
     * @param alarmId
     * @return
     */
    @Override
    public Map<String, Object> handling(String alarmId) {
        try {
            AlarmLedger alarmLedger = new AlarmLedger();
            alarmLedger.setAlarmId(alarmId);
            alarmLedger.setAlarmEndTime(new Date());
            alarmLedger.setIsSend(1);
            alarmLedgerMapper.updateByPrimaryKeySelective(alarmLedger);
        }catch (Exception e) {
            e.printStackTrace();
        }

        return success().getResult();
    }
}
